#include "StdAfx.h"
#include "tcp_syn_channel_impl.h"
#include "tcp_syn_event_handler.h"
#include "dll_object.h"

tcp_syn_channel_impl::tcp_syn_channel_impl(void)
{
	ev_ = new tcp_syn_event_handler(g_dll_obj->reactor_);
}

tcp_syn_channel_impl::~tcp_syn_channel_impl(void)
{
	if( ev_ )
	{
		ev_->close();
		delete ev_;
	}
}

void 
tcp_syn_channel_impl::set_dummy_http_tunnel_host(const char* host_name, int host_port)
{
	this->ev_->set_dummy_http_tunnel_host(host_name, host_port);
}

void 
tcp_syn_channel_impl::set_proxy(const char* ip, int port, const char* user, const char* pwd, int proxy_type)
{
	this->ev_->set_proxy(ip, port, user, pwd, proxy_type);
}

void 
tcp_syn_channel_impl::clr_proxy()
{
	this->ev_->clr_proxy();
}

bool 
tcp_syn_channel_impl::test_proxy(const char* proxy_host_name, int proxy_port, const char* proxy_auth, const char* forward_host_name, int forward_host_port, 
				const aot::inet::inet_time_t* tm_out, int* ret_code)
{
	ACE_INET_Addr proxy_addr(proxy_port, proxy_host_name);
	ACE_INET_Addr forward_addr(forward_host_port, forward_host_name);

	return this->ev_->test_proxy(proxy_addr, proxy_auth, forward_addr, tm_out, ret_code);
}

int tcp_syn_channel_impl::connect(const char* ip, int port, int serv_type, const aot::inet::inet_time_t* tm_out)
{
	ACE_INET_Addr addr(port, ip);
	return this->ev_->connect(addr, serv_type, tm_out);
}

void 
tcp_syn_channel_impl::set_heartbeat_time(const aot::inet::inet_time_t* tm, const aot::inet::inet_time_t* max_tm_out)
{
	this->ev_->set_heartbeat_time(tm, max_tm_out);
}

int 
tcp_syn_channel_impl::send(aot::inet::ipacket* pkt, const aot::inet::inet_time_t* tm_out)
{
	return this->ev_->put_to_send_queue(pkt, tm_out);
}

int 
tcp_syn_channel_impl::recv(aot::inet::ipacket** pkt, const aot::inet::inet_time_t* tm_out)
{
	return this->ev_->get_from_recv_queue(pkt, tm_out);
}

void 
tcp_syn_channel_impl::close()
{
	return this->ev_->close();
}

void 
tcp_syn_channel_impl::set_send_buf_size(size_t size)
{
	this->ev_->set_send_buf_size(size);
}

void 
tcp_syn_channel_impl::set_recv_buf_size(size_t size)
{
	this->ev_->set_recv_buf_size(size);
}

aot::inet::inet_addr_t* 
tcp_syn_channel_impl::local_addr()
{
	return this->ev_->local_addr();
}

aot::inet::inet_addr_t* 
tcp_syn_channel_impl::remote_addr()
{
	return this->ev_->remote_addr();
}